<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link href="../../css/style.css" rel="stylesheet" type="text/css" />
  <!--axios-->
  <script type="text/javascript" src="../../js/axios.js"></script>
  <script type="text/javascript" src="../../js/jquery-3.3.1.js"></script>
  <script type="text/javascript" src="../../js/api.js"></script>
  <link rel="stylesheet" href="../../layui/css/layui.css">
  <script type="text/javascript" src="../../layui/layui.js"></script>
  <script>
    $(function (){
      addressMenuInit($("#country"),$("#city"))
      $("#uid").val(localStorage.getItem("uId"))
      $("#username").val(localStorage.getItem("username"))
      var time = dateFormat("yyyy-MM-dd hh:mm:ss", new Date())
      $("#creatDate").val(time)
      function dateFormat(format, date) {
        if (!format) return '';
        date = date || new Date();
        let dateMap = {
          y: date.getFullYear(),
          M: date.getMonth() + 1,
          d: date.getDate(),
          h: date.getHours(),
          m: date.getMinutes(),
          s: date.getSeconds(),
          S: date.getMilliseconds()
        };
        return format.replace(/(y+)|(M+)|(d+)|(h+)|(m+)|(s+)|(S+)/g, (a) => _add0(dateMap[a[0]], a.length))
      }

      function _add0(time, len) {
        time = time.toString();
        let l = time.length;
        return l < len ? '0'.repeat(len - l) + time : time;
      }
    })
  </script>
  <script>
    layui.use('layer', function(){
      var layer  = layui.layer

      function checkcustomName() {
        var flag=true;
        var customName = $("#customName").val();
        if (customName.length < 1 || customName.length > 30) {
          layer.msg('姓名必填，不能超过30个字符', {icon: 5});
          $("#customName").css({"border-color":"red"})
          flag=false;
        }else {
          $("#customName").css({"border-color":""})
        }
        return flag;
      }

      function checkcompany() {
        var flag=true;
        var company = $("#company").val();
        if (company.length < 1 || company.length > 30) {
          layer.msg('所属公司必填，不能超过30个字符', {icon: 5});
          $("#company").css({"border-color":"red"})
          flag=false;
        }else {
          $("#company").css({"border-color":""})
        }
        return flag;
      }

      function checktelephone() {
        var flag=true;
        var reg =/^[\S]{6,11}$/
        var telephone = $("#telephone").val();
        if (reg.test(telephone )==false) {
          layer.msg('联系方式必须6到12位，且不能出现空格', {icon: 5});
          $("#telephone").css({"border-color":"red"})
          flag=false;
        }else {
          $("#telephone").css({"border-color":""})
        }
        return flag;
      }

      function checkhomeAddress() {
        var flag=true;
        var homeAddress = $("#homeAddress").val();
        if (homeAddress.length < 1 || homeAddress.length > 130) {
          layer.msg('联系地址必填，不能超过130个字符', {icon: 5});
          $("#homeAddress").css({"border-color":"red"})
          flag=false;
        }else {
          $("#homeAddress").css({"border-color":""})
        }
        return flag;
      }

      $("#subsub").click(function (){
        var city=$("#city").val()
        var province=$("#country").val()
        if (province==0){
          layer.msg('请选择省份', {icon: 5});
          return false;
        }
        if (city==0||city=="请选择城市"){
          layer.msg('请选择城市', {icon: 5});
          return false;
        }

        if (checkcustomName()&&checkcompany()&&checktelephone()&&checkhomeAddress()){
          var data=$("#addC").serializeArray()
          axiosJson("post","/marketing/addMarketingCustom",data,null).then(function (){
            window.location.href='customerList.html'
          })
        }else {
          // layer.msg('请填完整', {icon: 5});
          return false;
        }
      })
      $("#homeAddress").blur(checkhomeAddress)
      $("#customName").blur(checkcustomName)
      $("#telephone").blur(checktelephone)
      $("#company").blur(checkcompany)
    })
  </script>
</head>

<body>
<div class="place"> <span>位置：</span>
  <ul class="placeul">
    <li>营销管理</li>
    <li>客户管理</li>
    <li>添加</li>
  </ul>
</div>
<div  class="formbody" >
  <div class="formtitle"><span>客户信息</span></div>
  <form  id="addC">
  <ul class="forminfo">
    <li>
      <label>姓名</label>
      <input name="customName" type="text" class="dfinput" value="" id="customName"/>
      <i>必填，不能超过30个字符</i>
    </li>
    <li>
      <label>性别</label>
      <cite>
          <input name="sex" type="radio" value="1" checked="checked" />男
          &nbsp;&nbsp;&nbsp;&nbsp;
          <input name="sex" type="radio" value="2" />女
      </cite>
    </li>
    <li>
      <label>所属公司名称</label>
      <input name="company" type="text" class="dfinput" value="" id="company"/>
       <i>必填，不能超过30个字符</i>
    </li>
    <li>
      <label>联系方式</label>
      <input name="telephone" type="text" class="dfinput" value="" id="telephone"/>
       <i>必填，不能超过30个字符</i>
    </li>
    <li>
      <label>联系地址</label>
      <input name="homeAddress" type="text" class="dfinput" value="" id="homeAddress"/>
       <i>必填，不能超过130个字符</i>
    </li>
    <li>
      <label>所属区域</label>
      <select class="dfselect" id="country" >
          <option>请选择</option>
          <option>北京</option>
          <option>江苏</option>
          <option>天津</option>
      </select>
      省
      <select class="dfselect" name="address" id="city">
          <option value="0">请选择城市</option>
      </select>
      市
      <i>必选</i>
    </li>
    <li>
      <label>描述</label>
      <textarea class="textinput" name="distract"></textarea>
      <i>可选</i>
    </li>
    <li>
      <label>状态</label>
      <select class="dfselect" name="status">
          <option value="1">可用</option>
          <option value="2">不可用</option>
        </select>
      <i>必选</i>
    </li>
    <li>
      <label>创建人</label>
      <input name="createId" type="text" value="" readonly="readonly" class="roinput" id="uid" style="display: none"/>
      <input name="" type="text" value="" readonly="readonly" class="roinput" id="username" />
      <i>不能编辑</i>
    </li>
    <li>
      <label>创建时间</label>
      <input name="createTime" type="text" value="" readonly="readonly" class="roinput" id="creatDate"/>
      <i>不能编辑</i>
    </li>
    <li>
      <label>&nbsp;</label>
      <input name="" type="button" class="btn" value="确定"  id="subsub"/>
      <input name="" type="button" class="btn" value="返回" onclick="window.location.href='customerList.html'"/>
    </li>
  </ul>
  </form>
</div>
</body>
</html>
